package fr.mathis.ouestcharlie;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Environment;

public class ToolsPartie {

	public static final int NB_GAMES = 30;

	public static File getTempFile(Context context, int n){  
		//create the directory
		final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );  
		if(!path.exists()){  
			path.mkdir();
		}  
		File f = new File(path, "WIW"+n+".jpg");  
		return f;
	} 

	public static void writeBitmap(Resources resources, Context c, int n, Bitmap b)
	{
		try{
			File f = getTempFile(c,n);
			if(!f.exists())
			{
				FileOutputStream out = new FileOutputStream(f.getAbsolutePath());
				b.compress(Bitmap.CompressFormat.JPEG, 90, out);
				out.flush();
				out.close();
			}
		}
		catch(Exception e)
		{e.printStackTrace();}
	}

	public static BitmapDrawable getImage(int numGame, Resources res, Context c)
	{
		Bitmap mBitmap = null;
		BitmapFactory.Options bfOptions=new BitmapFactory.Options();
		bfOptions.inDither=false;
		bfOptions.inPreferredConfig = Config.RGB_565;
		bfOptions.inSampleSize = 1;
		bfOptions.inTempStorage = new byte[16*1024];
		bfOptions.inPurgeable=true;
		if(numGame==0)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game0); 
		else if(numGame==1)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game1); 
		else if(numGame==2)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game2); 
		else if(numGame==3)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game3); 
		else if(numGame==4)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game4); 
		else if(numGame==5)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game5); 
		else if(numGame==6)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game6); 
		else if(numGame==7)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game7); 
		else if(numGame==8)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game8);
		else if(numGame==9)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game9);
		else if(numGame==10)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game10);
		else if(numGame==11)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game11);
		else if(numGame==12)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game12);
		else if(numGame==13)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game13); 
		else if(numGame==14)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game14); 
		else if(numGame==15)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game15); 
		else if(numGame==16)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game16); 
		else if(numGame==17)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game17); 
		else if(numGame==18)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game18); 
		else if(numGame==19)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game19); 
		else if(numGame==20)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game20);
		else if(numGame==21)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game21);
		else if(numGame==22)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game22);
		else if(numGame==23)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game23); 
		else if(numGame==24)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game24); 
		else if(numGame==25)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game25); 
		else if(numGame==26)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game26); 
		else if(numGame==27)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game27); 
		else if(numGame==28)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game28); 
		else if(numGame==29)
			mBitmap = BitmapFactory.decodeResource(res, R.drawable.game29); 

		return new BitmapDrawable(res, mBitmap);
	}
	
	public static String getYoutubeUrl(int numGame, Context c)
	{
		String s = "";
		if(numGame==0)
			 s = "http://www.youtube.com/watch?v=ZPsyjerlIEg";
		else if(numGame==1)
			 s = "http://www.youtube.com/watch?v=WP9F0hYjBPU";
		else if(numGame==2)
			s = "http://www.youtube.com/watch?v=lrbWyOzB--I";
		else if(numGame==3)
			s = "http://www.youtube.com/watch?v=gnEWOgMpvnM";
		else if(numGame==4)
			s = "http://www.youtube.com/watch?v=6dnPdiVm3Eo";
		else if(numGame==5)
			s = "http://www.youtube.com/watch?v=GpO7XoJ8TNE";
		else if(numGame==6)
			s = "http://www.youtube.com/watch?v=g5fLR30fFHQ";
		else if(numGame==7)
			s = "http://www.youtube.com/watch?v=b3M0iqz1xR8";
		else if(numGame==8)
			s = "http://www.youtube.com/watch?v=U5UWwNFRuj0";
		else if(numGame==9)
			s = "http://www.youtube.com/watch?v=5onWdU2G6GE";
		else if(numGame==10)
			s = "http://www.youtube.com/watch?v=EZdztv13VD4";
		else if(numGame==11)
			s = "http://www.youtube.com/watch?v=x_aXb5zFglw";
		else if(numGame==12)
			s = "http://www.youtube.com/watch?v=rMcp96MM4SA";
		else if(numGame==13)
			s = "http://www.youtube.com/watch?v=i_spbDwQS4k";
		else if(numGame==14)
			s = "http://www.youtube.com/watch?v=NM1RPu3XIMY";
		else if(numGame==15)
			s = "http://www.youtube.com/watch?v=ZauPv7OkjII"; 
		else if(numGame==16)
			s = "http://www.youtube.com/watch?v=VWZHLGP9Gwg";
		else if(numGame==17)
			s = "http://www.youtube.com/watch?v=aOsGP_rxEzg";
		else if(numGame==18)
			s = "http://www.youtube.com/watch?v=4-84pTgUbEw";
		else if(numGame==19)
			s = "http://www.youtube.com/watch?v=FGXuNMFzJk4";
		else if(numGame==20)
			s = "http://www.youtube.com/watch?v=q98P34DFlbA";
		else if(numGame==21)
			s = "http://www.youtube.com/watch?v=9Bsl8uR-R94";
		else if(numGame==22)
			s = "http://www.youtube.com/watch?v=-j09CurAYoU";
		else if(numGame==23)
			s = "http://www.youtube.com/watch?v=BNp3TmQE0bY";
		else if(numGame==24)
			s = "http://www.youtube.com/watch?v=hyL99OdZpVE";
		else if(numGame==25)
			s = "http://www.youtube.com/watch?v=c498113gaZk";
		else if(numGame==26)
			s = "http://www.youtube.com/watch?v=BDRROfYtyyQ";
		else if(numGame==27)
			s = "http://www.youtube.com/watch?v=hJcuPy6R2Ew"; 
		else if(numGame==28)
			s = "http://www.youtube.com/watch?v=TMZ5qibuE7w";
		else if(numGame==29)
			s = "http://www.youtube.com/watch?v=3cJjd7ugd7s";

		return s;
	}
	
	public static String getTitle(int numGame, Context c)
	{
		String s = "";
		if(numGame==0)
			 s = c.getString(R.string.game0); 
		else if(numGame==1)
			 s = c.getString(R.string.game1); 
		else if(numGame==2)
			 s = c.getString(R.string.game2); 
		else if(numGame==3)
			 s = c.getString(R.string.game3); 
		else if(numGame==4)
			 s = c.getString(R.string.game4); 
		else if(numGame==5)
			 s = c.getString(R.string.game5); 
		else if(numGame==6)
			 s = c.getString(R.string.game6); 
		else if(numGame==7)
			 s = c.getString(R.string.game7); 
		else if(numGame==8)
			 s = c.getString(R.string.game8);
		else if(numGame==9)
			 s = c.getString(R.string.game9);
		else if(numGame==10)
			 s = c.getString(R.string.game10);
		else if(numGame==11)
			 s = c.getString(R.string.game11);
		else if(numGame==12)
			 s = c.getString(R.string.game12);
		else if(numGame==13)
			 s = c.getString(R.string.game13); 
		else if(numGame==14)
			 s = c.getString(R.string.game14); 
		else if(numGame==15)
			 s = c.getString(R.string.game15); 
		else if(numGame==16)
			 s = c.getString(R.string.game16); 
		else if(numGame==17)
			 s = c.getString(R.string.game17); 
		else if(numGame==18)
			 s = c.getString(R.string.game18); 
		else if(numGame==19)
			 s = c.getString(R.string.game19); 
		else if(numGame==20)
			 s = c.getString(R.string.game20);
		else if(numGame==21)
			 s = c.getString(R.string.game21);
		else if(numGame==22)
			 s = c.getString(R.string.game22);
		else if(numGame==23)
			 s = c.getString(R.string.game23); 
		else if(numGame==24)
			 s = c.getString(R.string.game24); 
		else if(numGame==25)
			 s = c.getString(R.string.game25); 
		else if(numGame==26)
			 s = c.getString(R.string.game26); 
		else if(numGame==27)
			 s = c.getString(R.string.game27); 
		else if(numGame==28)
			 s = c.getString(R.string.game28); 
		else if(numGame==29)
			 s = c.getString(R.string.game29); 

		return s;
	}
	
	public static int getResThumbnail(int numGame)
	{
		int res = R.drawable.ic_launcher;
		if(numGame==0)
			res = R.drawable.thumb0;
		else if(numGame==1)
			res = R.drawable.thumb1;
		else if(numGame==2)
			res = R.drawable.thumb2;
		else if(numGame==3)
			res = R.drawable.thumb3;
		else if(numGame==4)
			res = R.drawable.thumb4;
		else if(numGame==5)
			res = R.drawable.thumb5;
		else if(numGame==6)
			res = R.drawable.thumb6;
		else if(numGame==7)
			res = R.drawable.thumb7;
		else if(numGame==8)
			res = R.drawable.thumb8;
		else if(numGame==9)
			res = R.drawable.thumb9;
		else if(numGame==10)
			res = R.drawable.thumb10;
		else if(numGame==11)
			res = R.drawable.thumb11;
		else if(numGame==12)
			res = R.drawable.thumb12;
		else if(numGame==13)
			res = R.drawable.thumb13;
		else if(numGame==14)
			res = R.drawable.thumb14;
		else if(numGame==15)
			res = R.drawable.thumb15;
		else if(numGame==16)
			res = R.drawable.thumb16;
		else if(numGame==17)
			res = R.drawable.thumb17;
		else if(numGame==18)
			res = R.drawable.thumb18;
		else if(numGame==19)
			res = R.drawable.thumb19;
		else if(numGame==20)
			res = R.drawable.thumb20;
		else if(numGame==21)
			res = R.drawable.thumb21;
		else if(numGame==22)
			res = R.drawable.thumb22;
		else if(numGame==23)
			res = R.drawable.thumb23;
		else if(numGame==24)
			res = R.drawable.thumb24;
		else if(numGame==25)
			res = R.drawable.thumb25;
		else if(numGame==26)
			res = R.drawable.thumb26;
		else if(numGame==27)
			res = R.drawable.thumb27;
		else if(numGame==28)
			res = R.drawable.thumb28;
		else if(numGame==29)
			res = R.drawable.thumb29;

		return res;
	}

	public static ArrayList<HashMap<String, String>> initRes(Context c) {
		ArrayList<HashMap<String, String>> resultats =  new ArrayList<HashMap<String, String>>();
		HashMap<String, String> map = new HashMap<String, String>();

		//x 0
		map.put("left", "470");
		map.put("right", "770");
		//y
		map.put("top", "80");
		map.put("bottom", "970");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 1
		map.put("left", "1130");
		map.put("right", "1170");
		//y
		map.put("top", "295");
		map.put("bottom", "350");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 2
		map.put("left", "1820");
		map.put("right", "1865");
		//y
		map.put("top", "830");
		map.put("bottom", "900");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 3
		map.put("left", "1675");
		map.put("right", "1705");
		//y
		map.put("top", "920");
		map.put("bottom", "975");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 4
		map.put("left", "1675");
		map.put("right", "1700");
		//y
		map.put("top", "640");
		map.put("bottom", "690");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 5
		map.put("left", "300");
		map.put("right", "335");
		//y
		map.put("top", "765");
		map.put("bottom", "836");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 6
		map.put("left", "1250");
		map.put("right", "1275");
		//y
		map.put("top", "625");
		map.put("bottom", "675");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 7
		map.put("left", "1000");
		map.put("right", "1025");
		//y
		map.put("top", "525");
		map.put("bottom", "565");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 8
		map.put("left", "475");
		map.put("right", "525");
		//y
		map.put("top", "965");
		map.put("bottom", "1025");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 9
		map.put("left", "410");
		map.put("right", "440");
		//y
		map.put("top", "915");
		map.put("bottom", "950");
		map.put("diff", c.getString(R.string.easy));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 10
		map.put("left", "1835");
		map.put("right", "1870");
		//y
		map.put("top", "170");
		map.put("bottom", "210");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 11
		map.put("left", "1395");
		map.put("right", "1425");
		//y
		map.put("top", "985");
		map.put("bottom", "1015");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 12
		map.put("left", "855");
		map.put("right", "885");
		//y
		map.put("top", "855");
		map.put("bottom", "880");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 13
		map.put("left", "395");
		map.put("right", "425");
		//y
		map.put("top", "855");
		map.put("bottom", "885");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 14
		map.put("left", "350");
		map.put("right", "375");
		//y
		map.put("top", "730");
		map.put("bottom", "755");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 15
		map.put("left", "1850");
		map.put("right", "1880");
		//y
		map.put("top", "750");
		map.put("bottom", "775");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 16
		map.put("left", "540");
		map.put("right", "565");
		//y
		map.put("top", "280");
		map.put("bottom", "305");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 17
		map.put("left", "95");
		map.put("right", "1020");
		//y
		map.put("top", "980");
		map.put("bottom", "1005");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 18
		map.put("left", "1225");
		map.put("right", "1255");
		//y
		map.put("top", "650");
		map.put("bottom", "680");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		map = new HashMap<String, String>();
		//x 19
		map.put("left", "1280");
		map.put("right", "1305");
		//y
		map.put("top", "495");
		map.put("bottom", "520");
		map.put("diff", c.getString(R.string.medium));
		resultats.add(map);

		
		map = new HashMap<String, String>();
		//x 20
		map.put("left", "1505");
		map.put("right", "1530");
		//y
		map.put("top", "665");
		map.put("bottom", "695");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);
		
		
		map = new HashMap<String, String>();
		//x 21
		map.put("left", "1565");
		map.put("right", "1600");
		//y
		map.put("top", "560");
		map.put("bottom", "595");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 22
		map.put("left", "1520");
		map.put("right", "1540");
		//y
		map.put("top", "960");
		map.put("bottom", "985");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 23
		map.put("left", "1225");
		map.put("right", "1260");
		//y
		map.put("top", "310");
		map.put("bottom", "350");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 24
		map.put("left", "1870");
		map.put("right", "1900");
		//y
		map.put("top", "40");
		map.put("bottom", "70");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 25
		map.put("left", "1090");
		map.put("right", "1115");
		//y
		map.put("top", "295");
		map.put("bottom", "315");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 26
		map.put("left", "340");
		map.put("right", "365");
		//y
		map.put("top", "810");
		map.put("bottom", "840");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 27
		map.put("left", "1750");
		map.put("right", "1780");
		//y
		map.put("top", "30");
		map.put("bottom", "60");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 28
		map.put("left", "1590");
		map.put("right", "1610");
		//y
		map.put("top", "595");
		map.put("bottom", "615");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	
		
		map = new HashMap<String, String>();
		//x 29
		map.put("left", "50");
		map.put("right", "75");
		//y
		map.put("top", "645");
		map.put("bottom", "670");
		map.put("diff", c.getString(R.string.hard));
		resultats.add(map);	

		return resultats;
	}

}
